package com.hys.authserver.auth;

import jakarta.annotation.Resource;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * 实现 UserDetailsService 接口的方法
 * 使用用户名查询用户在数据库的信息
 */

public class AuthUserDetailsService implements UserDetailsService {

    private final PasswordEncoder passwordEncoder;


    public AuthUserDetailsService(PasswordEncoder passwordEncoder) {
        this.passwordEncoder = passwordEncoder;
    }

    @Override
    public AuthUserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return AuthUserDetails.builder()
                .uid("admin")
                .username("admin")
                .phone("15701263021")
                .password(passwordEncoder.encode("admin"))
                .authorities("ROLE_ADMIN")
                .build();
    }
}